package com.cupk.service.impl;

import com.cupk.mapper.GradeMapper;
import com.cupk.mapper.RecordMapper;
import com.cupk.pojo.Grade;
import com.cupk.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class GradeServiceImpl implements GradeService {
    @Autowired
    private GradeMapper gradeMapper;
    @Autowired
    private RecordMapper recordMapper;

    @Override
    public Grade getGradeByStuAndMatch(Integer stuId, Integer matchId) {
        return gradeMapper.findGradeRecordByStuAndMatch(stuId, matchId);
    }

    @Override
    public List<Map<String,Object>> getListByMatchId(Integer matchId) {
        return gradeMapper.getListByMatchId(matchId);
    }

    @Override
    public void updateGrade(Grade l) {
        LocalDateTime now = LocalDateTime.now();
        gradeMapper.updateGrade(l,now);
    }

    @Override
    public void addGrade(Grade l) {
        LocalDateTime now = LocalDateTime.now();
        gradeMapper.addGrade(l,now);
    }

    @Override
    public Integer transferAwardToInteger(String awardName) {
        Integer res = 0;
        String prefix = awardName.substring(0, 2);
        String suffix = awardName.substring(2, 5);
        if (prefix.equals("省赛")) {
            res += 5;
        } else if (prefix.equals("国赛")) {
            res += 10;
        }

        if (suffix.equals("参与奖")) {
            res += 1;
        } else if (suffix.equals("优秀奖")) {
            res += 2;
        } else if (suffix.equals("三等奖")) {
            res += 3;
        } else if (suffix.equals("二等奖")) {
            res += 4;
        } else if (suffix.equals("一等奖")) {
            res += 5;
        } else if (suffix.equals("特等奖")) {
            res += 6;  // CSP
        }
        return res;
    }

    @Override
    public List<Map<String, Object>> awardLevelClassification(Integer matchId) {
        return gradeMapper.awardLevelClassification(matchId);
    }

    @Override
    public List<Grade> getAward(Integer stuId) {
        return gradeMapper.getAward(stuId);
    }


}
